<!DOCTYPE html>
<html>
    <head>
        <title>AGM活动奖励</title>
        <link rel="stylesheet" href="/static/weui.min.css">
        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
        <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style>
            .page, body{background-color: #fbf9fe}
            .page_title{color:#225fba}
            .hd{text-align:center}
            .weui_label{width:4em;}
            .bd{padding-bottom:30px;}
            .weui_cell_hd img, .weui_cell_ft img{height: 40px;}
            .weui_cell_bd {
                white-space: nowrap;
                overflow: auto;
            }              
            .floatright{
                float: right;
            }
            /* 
            Generic Styling, for Desktops/Laptops 
            */
            table { 
              width: 100%; 
              border-collapse: collapse; 
            }
            /* Zebra striping */
            tr:nth-of-type(odd) { 
              background: #eee; 
            }
            th { 
              background: #333; 
              color: white; 
              font-weight: bold; 
            }
            td, th { 
              padding: 6px; 
              border: 1px solid #ccc; 
              text-align: left; 
            }
            .weui_dialog{
                overflow: auto;
                max-height: 80%;
            }
            .weui_icon_toast_info:before{
                content: '\EA0B';
                color: #fff;
                font-size: 55px;
            }
            .weui_icon_toast_info{
                margin: 22px 0 0;
                display: block;
            }            
        </style>
    </head>
    <body>
        <div class="hd">
            <h3 class="page_title">AGM活动奖励</h1> 
        </div>
        <div class="bd">
            <div class="weui_cells_title">微信信息</div>
            <div class="weui_cells weui_cells_access">
                <a class="weui_cell" href="/sellerinfo?uid={{seller.id}}">
                    <div class="weui_cell_hd"><img src="{{seller.get('headimgurl') or '/static/images/getheadimg.png'}}"></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <p>{{seller.get('nickname')}}</p>
                    </div>
                    <div class="weui_cell_ft">微信ID:{{seller.get('wxid')}}</div>
                </a>
            </div>
            <div class="weui_cells_title">销售信息</div>
                <div class="weui_cells">
                    <div class="weui_cell">
                        <div class="weui_cell_bd weui_cell_primary">
                            <p>{{ seller.get('dealername')}}</p>
                        </div>
                        <div class="weui_cell_ft">{{ seller.get('shopname')}}</div>
                    </div>
                </div>
            <div class="weui_btn_area">
                {% if seller.get('accept') == 1 %}
                <button class="weui_btn weui_btn_primary" id="rewardbtn">奖励</button>{% else %}
                <button class="weui_btn weui_btn_primary weui_btn_disabled">已取消</button>{% endif %}
            </div>            
            <div class="weui_cells_title">销售奖励清单<span class="floatright">待奖励值:<span id="totalreward">{{ total }}</span></span></div>
            <div class="mylist">
            <div class="weui_cells_title">活动支付的清单</div>
            <div class="mylist">
                <table>
                    <thead>
                    <tr>
                        <th>时间</th>
                        <th>单号</th>
                        <th>金额</th>
                        <th>奖励</th>
                        <th>详情</th>
                    </tr>
                    </thead>
                    <tbody>
                        {% for r in reward_wait %}
                        <tr>
                            <td>{{ r.get('time_end').strftime('%H:%M %y%m%d')}}</td>
                            <td>**{{ r.get('transaction_id')[-4:] }}</td>
                            <td>{{ r.get('total_fee') }}</td>
                            <td>{{ r.get('reward') }}</td>
                            <td did="{{r.id}}" dpid="{{ r.get('product_id')}}" dcost="{{ r.get('total_fee') }}" dreward="{{r.get('reward')}}" dtime="{{ r.get('time_end').strftime('%Y-%m-%d %H:%M') }}" dtid="{{ r.get('transaction_id') }}" doid="{{ r.get('out_trade_no') }}" drewardtime="{{ pDT(r.get('rewardtime'), '%Y-%m-%d %H:%M') if r.get('rewardtime') else '未奖励'}}"><i class="{% if r.get('rewardstat') == -1 %}weui_icon_warn{% else %}weui_icon_waiting{% endif %}"></i></td>
                        </tr>{% endfor %}
                        {% for r in rewarded %}
                        <tr>
                            <td>{{ r.get('time_end').strftime('%H:%M %y%m%d')}}</td>
                            <td>**{{ r.get('transaction_id')[-4:] }}</td>
                            <td>{{ r.get('total_fee') }}</td>
                            <td>{{ r.get('reward') }}</td>
                            <td did="{{r.id}}" dpid="{{ r.get('product_id')}}" dcost="{{ r.get('total_fee') }}" dreward="{{r.get('reward')}}" dtime="{{ r.get('time_end').strftime('%Y-%m-%d %H:%M') }}" dtid="{{ r.get('transaction_id') }}" doid="{{ r.get('out_trade_no') }}" drewardtime="{{ pDT(r.get('rewardtime'), '%Y-%m-%d %H:%M') if r.get('rewardtime') else '未奖励'}}"><i class="weui_icon_success"></i></td>
                        </tr>{% endfor %}                          
                    </tbody>
                </table>
            </div>
            </div>
        </div>       
        <div class="weui_dialog_alert" id="dialog2" style="display:none">
            <div class="weui_mask"></div>
            <div class="weui_dialog">
                <div class="weui_dialog_hd"><strong class="weui_dialog_title">弹窗标题</strong></div>
                <div class="weui_dialog_bd">弹窗内容，告知当前页面信息等</div>
                <div class="weui_dialog_ft">
                    <a class="weui_btn_dialog primary">确定</a>
                </div>
            </div>
        </div>
        <div id="toast" style="display: none;">
            <div class="weui_mask_transparent"></div>
            <div class="weui_toast">
                <i class="weui_icon_toast"></i>
                <p class="weui_toast_content">已完成</p>
            </div>
        </div>
        <div id="loadingToast" class="weui_loading_toast" style="display:none;">
            <div class="weui_mask_transparent"></div>
            <div class="weui_toast">
                <div class="weui_loading">
                    <!-- :) -->
                    <div class="weui_loading_leaf weui_loading_leaf_0"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_1"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_2"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_3"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_4"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_5"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_6"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_7"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_8"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_9"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_10"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_11"></div>
                </div>
                <p class="weui_toast_content">数据加载中</p>
            </div>
        </div>        
    </body>    
    <script>
        dialog2 = function(title, content, sucfunc){
            var self = $('#dialog2')
            self.find('.weui_dialog_title').text(title)
            self.find('.weui_dialog_bd').html(content)
            var clickfunc = sucfunc?sucfunc:function(){self.hide();}
            self.find('.weui_btn_dialog.primary').one('click', clickfunc)
            self.show()
        }
        $('#acceptbtn').click(function(e){
            var self = $(this)
            var sellerid = self.attr('seller_id')
            $.post('manage?action=acceptseller&sellerid='+sellerid).done(function(data){
                console.info(data)
                if(data=='acceptsuccess'){
                    dialog2('通过审核成功', '<i class="weui_icon_msg weui_icon_success"></i><div>已经成功接受该销售用户的审核<br/>点击确定键返回销售用户列表</div>', function(){location.replace('sellerlist')})
                }
            })
        })
                 
        $(document).on('click', '.statbtn', function(){
            var self = $(this).find('i')
            displayMore(self)
            $('.weui_mask').one('click', function(){
                $(this).parent().hide()
            })
        })
        mymessage = function(content){
            var toast = $('#toast')
            toast.find('.weui_toast_content').html(content)
            toast.find('i').attr('class', 'weui_icon_toast_info')
            toast.show()
            setTimeout("$('#toast').hide()", 1500);
        }
        mymessage_suc = function(content){
            var toast = $('#toast')
            toast.find('.weui_toast_content').html(content)
            toast.find('i').attr('class', 'weui_icon_toast')
            toast.show()
            setTimeout("$('#toast').hide()", 1500);    
        }
        myloadingshow = function(title){
            var toast = $('#loadingToast')
            toast.find('.weui_toast_content').text(title)
            toast.show()
        }
        myloadinghide = function(){$('#loadingToast').hide()}        
        $('#rewardbtn:not(.weui_btn_disabled)').click(function(){
            var rewardids = ''
            $('i.weui_icon_waiting').each(function(){
                rewardids += '|' + $(this).parent().attr('did')
            })
            if(rewardids==''){
                mymessage('当前没有<br/>可奖项目')
                return
            }
            console.info(rewardids)
            var self = $(this)
            self.addClass('weui_btn_disabled')
            myloadingshow('奖励中...')
            $.post('?action=rewardseller', {'rewardids': rewardids}, null, 'json').done(function(data){
                console.info('suc:' + data, data.sucids, data.failids)
                for(var i=0;i<data.sucids.length;i++){
                    $('td[did='+data.sucids[i][0]+']').attr('drewardtime', data.sucids[i][1]).find('i').attr('class', 'weui_icon_success')
                }
                for(var i=0;i<data.failids.length;i++){
                    $('td[did='+data.failids[i]+']').find('i').attr('class', 'weui_icon_warn')
                }
                myloadinghide()
                $('#totalreward').text(parseInt($('#totalreward').text())-data.rewardsum)
                self.removeClass('weui_btn_disabled')
                dialog2('奖励完成', '<i class="weui_icon_success weui_icon_msg"></i><div>本次奖励完成<br>共奖励'+data.rewardsum+'</div>')
            }).fail(function(data){
                console.info('fai:' + data.responseText)
                myloadinghide()
                self.removeClass('weui_btn_disabled')
                mymessage('未知错误')
            })
        })
        showrecentmore = function(self){
            var content = '<table><thead><tr><th>销售产品</th><th>销售时间</th></tr></thead><tbody>'
            self.nextAll('.recent_record').each(function(){
                content += '<tr><td>'+$(this).attr('data-spname')+'</td><td>'+$(this).attr('data-date')+'</td></tr>'
            })            
            content += '</tbody></table>'
            dialog2('销售详情', content)
        }
        $(document).on('click', '.c_recent_btn', function(){
            var self = $(this)
            showrecentmore(self)
            $('.weui_mask').one('click', function(){
                $(this).parent().hide()
            })            
        })
        $('td[dtime]').css('cursor','pointer')
        $(document).on('click', 'td[dtime]', function(){
            var self = $(this)
            var content = '<div style="text-align:left;color:black">'
            var dtags = [
                ['dpid', '支付二维码'], 
                ['dcost', '交易金额(元)'], 
                ['dtime', '支付时间'], 
                ['dtid', '交易单号'], 
                ['doid', '商户订单号'], 
                ['dreward', '奖励金额'],
                ['drewardtime', '奖励时间']
            ]
            for(i in dtags){
                content += '<div class="weui_cells_title">'+dtags[i][1]+'</div><div class="weui_cells"><div class="weui_cell"><div class="weui_cell_bd weui_cell_primary"><p>'+self.attr(dtags[i][0])+'</p></div></div></div>'
            }           
            content += '</div>'
            // console.info(content)
            dialog2('订单详情', content)
        })        
    </script>
<html>